/* ---------------------------------------------------------------------------
** This software is in the public domain, furnished "as is", without technical
** support, and with no warranty, express or implied, as to its usefulness for
** any purpose.
**
** BencodingHandler.h
** Declare BencodingData class and some BencodingData handler funcs.
**
** Author: wuwei0509@gmail.com
** -------------------------------------------------------------------------*/

#ifndef _BENCODINGHANDLER_H
#define _BENCODINGHANDLER_H

//includes
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

//macros
typedef enum{
	BENCODINGTYPE_UNKNOWN,
	BENCODINGTYPE_INT,
	BENCODINGTYPE_STRING,
	BENCODINGTYPE_LIST,
	BENCODINGTYPE_DICT
}BENCODINGTYPE;

//class
//pre declaration
class DictPair;

class BencodingData{
public:
	BencodingData():intValue(0){}

	void setType(BENCODINGTYPE _type){type = _type;}
	void setValue(string _value){strValue = _value;}
	void setValue(__int64 _value){intValue = _value;}

	BENCODINGTYPE getType(){return type;}
	string getStrValue(){return strValue;}
	__int64 getIntValue(){return intValue;}
	vector<BencodingData> & getListValue(){return listValue;} 
	vector<DictPair> & getDictValue(){return dictValue;}
private:
	BENCODINGTYPE type;
	string strValue;
	__int64 intValue;
	vector<BencodingData> listValue;
	vector<DictPair> dictValue;
};

class DictPair{
public:
	DictPair(string _key, BencodingData _value) : 
	key(_key), value(_value){}
private:
	string key;
	BencodingData value;
};

class BencodingHandler {
	//methods
public:
	//constructor
	BencodingHandler(ifstream & in):m_in(in){}
	//handlers
	static string ReadString(char * seedContent, __int64& startPos);
	static __int64 ReadInt(char * seedContent, __int64& startPos);
private:
	
	//members
public:

private:
	ifstream & m_in;

};


#endif